package org.tagging.service.impl.philippines;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.tagging.dao.philippines.UnknownWordPhilippinesMapper;
import org.tagging.model.UnknownWord;
import org.tagging.model.UnknownWordPhilippines;
import org.tagging.service.UnknownWordService;
import org.tagging.service.impl.other.ClientUserServiceImpl;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class UnknownWordPhilippinesServiceImpl implements UnknownWordService<UnknownWordPhilippines> {
    @Resource
    private UnknownWordPhilippinesMapper unknownWordPhilippinesMapper;
    @Autowired
    private ClientUserServiceImpl userService;


    @Override
    public List<UnknownWordPhilippines> queryByTagId(Integer id) {
        return unknownWordPhilippinesMapper.queryByTagId(id);
    }

    @Override
    public void update(UnknownWord unknownWord) {
        Integer userId = userService.retrieveCurrentUserId();
        unknownWord.setUpdateTime(LocalDateTime.now());
        unknownWord.setUpdateBy(userId);
        unknownWordPhilippinesMapper.updateSelective(unknownWord);

    }

    @Override
    public UnknownWord queryById(Integer id) {
        return unknownWordPhilippinesMapper.queryById(id);
    }

    @Override
    public void add(UnknownWord unknownWord) {
        Integer userId = userService.retrieveCurrentUserId();
        unknownWord.setUpdateTime(LocalDateTime.now());
        unknownWord.setUpdateBy(userId);
        unknownWordPhilippinesMapper.insertSelective(unknownWord);

    }

    @Override
    public List<UnknownWordPhilippines> queryByTimePeriod(LocalDateTime startTime, LocalDateTime endTime, int mode) {
        return unknownWordPhilippinesMapper.queryByTimePeriod(startTime,endTime,mode);
    }
}
